﻿#!/usr/bin/env python
#coding:utf-8
from probe.core.level import *
from commands import *
import os
import time

def mysqlbinlog_bak(args):
    '''监控mysql二进制备份(备份服务器专用)'''
    errorlist = {}
    binlogbak = "/binlogbak"
    os.cwd(binlogbak)
    for bakdir in os.listdir(binlogbak):
        lastfile = getoutput("ls -t %s/mysql-bin*|head -1"%bakdir)
        lastfile_mtime = int(os.path.getmtime(lastfile))
        nowtime = int(time.time())
        t = 400 - (nowtime - lastfile_mtime)
        if t > 0:
            errorlist[bakdir]=['备份失败', '']
    if errorlist:
        return WarningData(errorlist)
    return InfoData(errorlist)
   
if __name__ == '__main__':
    print mysqlbinlog_bak('')
